<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>美食信息</title>
  <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
</head>
<body>
     <h1 align="center" style="margin-right:20px">美食信息列表</h1>
    <form method="post" action="" class="col-md-4 control-label col-md-offset-5">
      请输入美食名:
      <input type="text" name="key">
      <input type="submit" name='search' value="搜索" class="btn btn-success">
    </form>
     <table align="center" class="table table-bordered">
     <tr>
         <th class="text-center">美食编号</th>
         <th class="text-center">美食名</th>
         <th class="text-center">美食类型</th>
         <th width="80" class="text-center">美食图片</th>
         <th class="text-center">美食简介</th>
         <th class="text-center">操作 <a href="admin.php?c=food&m=form">添加</a></th>
     </tr>


    <?php
      $i=1;
     	foreach($data['foods'] as $row){
			echo'<tr>';
			echo '<td class="text-center">'.$i++.'</td>';
			echo'<td class="text-center">'.$row['foodname'].'</td>';
			switch($row['tid']){
				case'1':$tp="川菜"; break;
				case'2':$tp="徽菜"; break;
				case'3':$tp="鲁菜"; break;
        case'4':$tp="闽菜"; break;
        case'5':$tp="苏菜"; break;
        case'6':$tp="湘菜"; break;
        case'7':$tp="粤菜"; break;
        case'8':$tp="浙江菜"; break;
				default:$tp="不知道";
			}
			echo '<td class="text-center">'.$tp.'</td>';
			echo '<td align="center"><img src='."upload/".$row['pic'].' width=60 height=80 alt="海报" class="img-circle"></td>';
			echo'<td class="text-center">'.$row['intro'].'</td>';
			echo '<td class="text-center"><a href="admin.php?c=food&m=mod&id='.$row['vid'].'" class="btn btn-success" href="#" role="button">修改</a>|<a href="admin.php?c=food&m=del&id='.$row['vid'].'" onClick="return confirm(\'确定要删除吗？\');" class="btn btn-danger" href="#" role="button">删除</a></td>';
            echo '</tr>';

        }
        echo '</table>';
    if ($rowsperpage>=$totalrows) 
        $totalpages=1;
     else{
       $totalpages=ceil($totalrows/$rowsperpage);
    }
    //如果不是第一页，则显示第一页和上一页的超链接，否则只显示文字
    //echo '<nav><u1 class="pager">';
    if ($page>1) {
      $first="<a href=?page=1&key={$key}>首页</a>";
      $pre="<a href=?page=".($page-1)."&key={$key}>上一页</a>";
    }else{
      $first='首页';
      $pre='上一页';
   }
   //如果不是最后一页，则显示下一页和最后一页的超链接，否则只显示文字
    if ($page<$totalpages) {
      $last="<a href=?page=$totalpages&key={$key}>尾页</a>";
      $next="<a href=?page=".($page+1)."&key={$key}>下一页</a>";
    }else{
      $last='尾页';
      $next='下一页';
    }
    echo "<table align='center'><tr>";
    echo "<td>共{$totalrows}类美食</td>";
    echo "<td>$first"."&nbsp;&nbsp;"."$pre"."&nbsp;&nbsp;";
    for($i=1;$i<=$totalpages;$i++){
      echo "<a href='?page=$i&key={$key}'>第{$i}页</a>&nbsp;&nbsp;";
    }
    echo "$next"."&nbsp;&nbsp;"."$last&nbsp;";
    //输出第几页/共几页
    echo "<font color=red>";
    echo "第".$page."页/共".$totalpages."页";
    echo "</font></td>";
    //输出转到几页的表单
    ?>
</table>
</body>
</html>